package org.example.weather.bigscreen.core.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.example.weather.bigscreen.core.api.WeatherAreaApi;
import org.example.weather.bigscreen.core.api.dto.AreaDTO;
import org.example.weather.bigscreen.core.service.WeatherAreaService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created on 2022-07-22.
 *
 * @author chenyu
 */
@RestController
@Slf4j
@RequestMapping("weather-area")
public class WeatherAreaController implements WeatherAreaApi {
    private WeatherAreaService weatherAreaService;

    public WeatherAreaController(final WeatherAreaService weatherAreaService) {
        this.weatherAreaService = weatherAreaService;
    }


    @Override
    public List<AreaDTO> selectAll(final Boolean enabled) {

        return weatherAreaService.selectAll(enabled);
    }

    @Override
    public Map<String, Boolean> selectWeatherAreaStatus(final List<String> areaIds) {
        if (CollectionUtils.isNotEmpty(areaIds)) {
            return weatherAreaService.selectByAreaIds(areaIds);
        } else {
            return new HashMap<>();
        }
    }
}
